/**
 * 
 */
package com.sf.osms.dep.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sf.osms.dep.biz.IAgentConfigBiz;
import com.sf.osms.dep.dao.IAgentConfigDao;
import com.sf.osms.dep.domain.AgentConfig;
import com.sf.osms.dep.processor.util.CollectionUtil;


/**
 * @author sfhq1469
 *
 */
@Service("agentConfigBizImpl")
@Transactional
public class AgentConfigBizImpl implements IAgentConfigBiz{

	@Autowired
	private IAgentConfigDao agentConfigDao;

	

	@Override
	public List<AgentConfig> queryAgentConfigByAgentId(Long id) {
		return agentConfigDao.queryAgentConfigByAgentId(id);
	}
	
	@Override
	public String querySFCode(String agentId , String agentCode) {
		return agentConfigDao.querySFCode(agentId,agentCode);
	}

	@Override
	public List<String> querySFCode(String agentName) {
		return agentConfigDao.querySFCode(agentName);
	}

	@Override
	@Transactional
	public void addConfigTypesBatch(List<AgentConfig> newAgentConfigs) {
		if(!CollectionUtil.isEmpty(newAgentConfigs)){
			List<String> oldAgentCodes = agentConfigDao.queryAgentCodeByAgentId(newAgentConfigs.get(0).getAgentId());
			for (AgentConfig agentConfig : newAgentConfigs) {
				String agentCode = agentConfig.getAgentCode();
				if(oldAgentCodes.contains(agentCode)){
					//删除相应的代理配置
					AgentConfig a = new AgentConfig();
					a.setAgentCode(agentCode);
					a.setAgentId(agentConfig.getAgentId());
					a.setConfigType(1);
					agentConfigDao.remove(a);
				}
			}
			
			//进行批量
			agentConfigDao.saveBatch(newAgentConfigs);
		}
		
	}
	
	
}
